home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
stv.lha
/
STV
/
ISA
/
artifact
/
remfile.st
< prev
next >
Wrap
Text File
|
1993-07-23
|
1KB
|
48 lines
"
File Remove Change by Tom Wrensch & Gene Korienek
I find that I often want to make sure that a file
has been removed from the disk. Simply using
File remove: 'filename.ext' will cause a walkback
if 'filename.ext' doesn't exist. My fix is to
define a new File class message remove:ifAbsent:
which takes a block as its second argument. If
the file is on the disk, fine simply remove it -
if it isn't on the disk then evaluate the block
passed in the second argument.
For example lets say I want to remove any old
versions of the file 'test1.txt' before reuse
that name. I could just do this:
File remove: 'test1.txt' ifAbsent: [].
No blow up ! If I want to do something more
complicated when the file isn't there I can
put what I want to happen in the block."!
!Dos methods !
hasError
"Answer true if calling dosError: with
the current register set would cause
a walkback."
^((registers at: 17) bitAnd: 1) = 1! !
!File class methods !
remove: aString ifAbsent: aBlock
"Erase the file named aString. If I can't
(because it's absent or locked) evaluate
aBlock."
| aDos old |
aDos := Dos new.
old := aString asAsciiZ.
aDos setReg: 6 to: old;
setReg: 3 to: old;
setRegHigh: 0 to: 16r41;
interrupt: 16r21.
aDos hasError ifTrue: aBlock! !